<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var applyOperations = function (nums) {
      const n = nums.length;
      for (let i = 0; i < n - 1; i++) {
        if (nums[i] === nums[i + 1]) {
          nums[i] *= 2;
          nums[i + 1] = 0;
        }
      }
      const values = nums.filter(it => it !== 0);
      return values.concat(new Array(n - values.length).fill(0));
    };
    console.log(applyOperations([1, 2, 2, 1, 1, 0]));
  </script>
</body>

</html>